package com.eazyimage.lab.controller;

import com.eazyimage.lab.entity.Response;
import com.eazyimage.lab.entity.User;
import com.eazyimage.lab.mapper.VerifygenMapper;
import com.eazyimage.lab.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import static com.eazyimage.lab.service.SH256Service.getSHA256Str;


@RestController
public class LoginController {
    @Autowired
    LoginService service;


    @RequestMapping("/login")
    public Response login(@RequestParam("username") String username,
                          @RequestParam("password") String password){
        User user = service.login(username,password);
        if (user!=null){
            return Response.success();
        }
        return Response.fail();
    }

    @RequestMapping("/ggtest")
    @ResponseBody
    public String ggtest(@RequestParam("Datasetid") String datasetid){
       // return vv.Toverify(datasetid);
        return "";
    }


    @RequestMapping("/register")
    public Response register(@RequestParam("username") String username,
                             @RequestParam("password") String password){
        int usernum = service.registeronly(username);
        if (usernum == 0){
            service.register(username,password);
            return Response.success();
        }
        return Response.fail();
    }



}
